﻿using DevExpress.XtraGrid.Demos.util;
using Luna小店.DTO;
using Luna小店.UC.面料库存.库存记录.service;
using mendian;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Luna小店.UC.面料库存.盘点.service
{
    public class 盘点Service
    {
        public static void post盘盈入库(DTO盘盈入库 DTO盘盈入库)
        {
            RestCall.PostHttp(
                URL.接口url + "/inventory/stockInStock", 
                FunctionHelper.JsonSerialization(
                    DTO盘盈入库
                    )
                );
        }

        public static void post盘亏出库(StockOutDTO StockOutDTO)
        {
            RestCall.PostHttp(
                URL.接口url + "/inventory/inventoryStockOut", 
                FunctionHelper.JsonSerialization(
                    StockOutDTO
                    )
                );
        }

    }

    public class DTO盘盈入库
    {
        public String orderId { get; set; } //  入库单id
        public String stockInType { get; set; } //  出入库类型
        public DateTime stockInDate { get; set; }  //  入库时间
        public List<DTO盘盈入库分录> orderStockInEntryDTOS { get; set; } = new List<DTO盘盈入库分录>();
        public DTO盘盈入库(String stockInType, DateTime stockInDate, List<DTO采购分录> DTO采购分录s)
        {
            this.orderId = new FunctionHelper().Uuid;
            this.stockInType = stockInType;
            this.stockInDate = stockInDate;
            foreach (DTO采购分录 DTO采购分录 in DTO采购分录s)
            {
                orderStockInEntryDTOS.Add(new DTO盘盈入库分录(DTO采购分录));
            }
        }
    }
    public class DTO盘盈入库分录
    {
        public String entryId { get; set; }  //  分录ID
        public String materialId { get; set; }     //  物料id
        public String materialCode { get; set; }    //  物料编码
        public double quantity { get; set; }    //  数量
        public double stockInPrice { get; set; }     //  单价
        private double stockInUnitPrice { get; set; }   //  入库加权平均价格

        public DTO盘盈入库分录(DTO采购分录 DTO采购分录)
        {
            this.entryId = new FunctionHelper().Uuid;
            this.materialId = DTO采购分录.id;
            this.materialCode = DTO采购分录.materialNo;
            this.quantity = DTO采购分录.quantity;
            this.stockInPrice = DTO采购分录.unitPrice;
        }
    }

    public class StockOutDTO
    {
        public String orderId { get; set; } //  出库单id
        public DateTime stockOutDate { get; set; } //  出库时间
        public List<StockOutEntryDTO> stockOutEntryDTOS { get; set; } = new List<StockOutEntryDTO>();
        public StockOutDTO(DateTime stockOutDate, List<DTO采购分录> DTO出库分录s)
        {
            this.orderId = new FunctionHelper().Uuid;
            this.stockOutDate = stockOutDate;
            foreach (DTO采购分录 DTO采购分录 in DTO出库分录s)
            {
                stockOutEntryDTOS.Add(new StockOutEntryDTO(DTO采购分录));
            }
        }

    }
    public class StockOutEntryDTO
    {
        public String entryId { get; set; } //  出库单分录ID
        public String materialId { get; set; }   //  物料id
        public String materialCode { get; set; }    //  物料编码
        public double quantity { get; set; }    //  数量
        public double stockOutUnitPrice { get; set; }  //  入库加权平均价格
        public StockOutEntryDTO(DTO采购分录 DTO采购分录)
        {
            this.entryId = new FunctionHelper().Uuid;
            this.materialId = DTO采购分录.id;
            this.materialCode = DTO采购分录.materialNo;
            this.quantity = DTO采购分录.quantity;
            this.stockOutUnitPrice = DTO采购分录.unitPrice;
        }

    }
}
